package com.baiqi.rabbitmq.rabbitmq.topic;

import com.baiqi.rabbitmq.rabbitmq.utils.RabbitConstant;
import com.baiqi.rabbitmq.rabbitmq.utils.RabbitUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

public class WeatherBureau {
    public static void main(String[] args) throws IOException, TimeoutException {
        LinkedHashMap<String, String> area = new LinkedHashMap<>();
        area.put("china.hunan.changsha.20201127","中国湖南长沙20201127天气数据");
        area.put("china.hubei.wuhan.20201127","中国湖北武汉20201127天气数据");
        area.put("china.hunan.zhuzhou.20201127","中国湖南株洲20201127天气数据");
        area.put("us.cal.lsj.20201127","美国加州洛杉矶20201127天气数据");

        area.put("china.hunan.changsha.20201128","中国湖南长沙20201128天气数据");
        area.put("china.hubei.wuhan.20201128","中国湖北武汉20201128天气数据");
        area.put("china.hunan.zhuzhou.20201128","中国湖南株洲20201128天气数据");
        area.put("us.cal.lsj.20201128","美国加州洛杉矶20201128天气数据");

        Connection connection = RabbitUtils.getConnection();
        Channel channel = connection.createChannel();
        Iterator<Map.Entry<String, String>> iterator = area.entrySet().iterator();
        while (iterator.hasNext()){
            Map.Entry<String, String> next = iterator.next();
            channel.basicPublish(RabbitConstant.EXCHANGE_WEATHER_TOPIC,next.getKey(),null,next.getValue().getBytes(StandardCharsets.UTF_8));
        }
        channel.close();
        connection.close();
    }

}
